package com.javase.regular;

import com.sun.org.apache.bcel.internal.generic.InstructionList;
import com.sun.org.apache.xalan.internal.xsltc.compiler.Pattern;

import java.util.regex.Matcher;

/**
 * java正则表达式练习
 *
 * @author liyanhao
 * @create 2022-06-30 16:16
 */
public class RegularExpression {
    public static void main(String[] args) {
        String ss = "thisistext";
        String pattern = ".+is.+";
        boolean matches = ss.matches(pattern);
        System.out.println(ss + "\t" + pattern + "\t" + matches);
        ss = "   is  ";
        pattern = "\\s+is\\s+";
        matches = ss.matches(pattern);
        System.out.println(ss + "\t" + pattern + "\t" + matches);
        System.out.println(ss + "\t" + pattern + "\t" + matches);
        ss = "123.11";
        pattern = "^\\d+(\\.\\d+)?";
        matches = ss.matches(pattern);
        System.out.println(ss + "\t" + pattern + "\t" + matches);
        ss = "This order was placed for QT3000! OK?";
        pattern = "^\\d+";
        System.out.println(ss + "\t" + pattern + "\t" + matches);
        ss = "This order was placed for QT3000! OK?";
        pattern = "(\\\\D*)(\\\\d+)(.*)";

        // 按指定模式在字符串查找
        ss = "This order was placed for QT3000! OK?";
        pattern = "(\\D*)(\\d+)(.*)";
        matches = ss.matches(pattern);
        System.out.println(ss + "\t" + pattern + "\t" + matches);



    }
}
